package com.sxx.mall.search.controller;

import com.sxx.mall.search.service.MallSearchService;
import com.sxx.mall.search.vo.SearchParam;
import com.sxx.mall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @Auther: sunxx
 * @Date: 2024/8/8 - 08 - 08 - 10:39
 * @Description: com.sxx.mall.search.controller
 * @version: 1.0
 */
@Controller
public class SearchController {

    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping(value = {"/list.html","/","index.html"})
    public String listPage(SearchParam param, Model model){
        SearchResult searchResult = mallSearchService.search(param);
        model.addAttribute("result",searchResult);
        return "index";
    }

    @GetMapping("/search.html")
    public String listPage(String keyword,Model model){
        SearchResult searchResult = mallSearchService.searchByKeyword(keyword);
        model.addAttribute("result",searchResult);
        return "index";
    }
}
